#ifndef __CYNFSM__H__
#define __CYNFSM__H__

#ifdef __cplusplus
extern "C" {
#endif


#include "cynStateMachinetype.h"


typedef struct 
{
    cynStateMachineFunc entry;
    cynStateMachineFunc process;
    cynStateMachineFunc exit;
}cynFsmFuncs;

typedef struct 
{
    mu8 currentStatus;
    mu8 nextStatus;
#ifndef STATEMACHINE_USE_MIN
    mu32 delay;
    mu32 delay_cnt;
    mu32 funArg;
    mu32 funReturn;
#endif
    mu8 stateNum;
    cynFsmFuncs stateProcess[];
}cynFsmClass;


//define a static fsm ojb by name and size(state num)
#define DEF_CYN_FSM_OBJ_STATIC(NAME,SIZE)                         \
mu8 cynFSMOBJarray_##NAME[sizeof(cynFsmClass)+(SIZE*sizeof(cynFsmFuncs))];    \
cynFsmClass *cynFSMOBJ_##NAME = (cynFsmClass *)cynFSMOBJarray_##NAME;

//use fsm ojb by name 
#define CYN_FSM_OBJ(NAME)   cynFSMOBJ_##NAME     

extern void cynFsmTick(cynFsmClass *fobj,mu32 ms);
extern void cynFsmObjInit(cynFsmClass *fobj,mu32 stanum);
extern void cynFsmRun(cynFsmClass *fobj);
extern void cynFsmRegister(cynFsmClass *fobj,mu8 stanum,cynStateMachineFunc entry,cynStateMachineFunc process,cynStateMachineFunc exit);
extern void cynFsmUnregister(cynFsmClass *fobj,mu8 stanum);
extern void cynFsmJump(cynFsmClass *fobj,mu8 next,mu32 delay);
extern mu32 cynFsmObjGetRes(cynFsmClass *fobj);
extern void cynFsmObjSetArg(cynFsmClass *fobj,mu32 arg);
extern mu8 cynFsmObjGetStatus(cynFsmClass *fobj);
#ifdef __cplusplus
}
#endif
#endif